//
//  VariableView.swift
//  swiftStudy
//
//  Created by Zhang on 2021/3/17.
//

import SwiftUI

struct VariableView: View {
    
    private let code_1:String
    
    init() {
        code_1 =
            "//声明一个变量\n" +
            "var str:String = \"Hello, playground\"\n" +
            "//声明一个常量\n" +
            "let name:String = \"Zhang\"\n" +
            "//声明三个Int类型的变量\n" +
            "var a,b,c:Int\n" +
            "\n" +
            "//变量可重新赋值\n" +
            "str = \"hello\"\n" +
            "//name = \"Li\" 常量重新赋值编译错误\n"
    }
    
    var body: some View {
        ScrollView(.vertical){
            //垂直布局,alignment: .leading内容居左,spacing: 50元素间距
            VStack(alignment: .leading, spacing: 5){
                Section(header: SectionHeaderView(title: "基本概念")){
                    CommonTextView(content: "在Swift中,let关键字和var关键字分别用来表示常量和变量,其作用是为某个量值取一个名称,在其有效的作用域内,可通过这些名称进行引用.变量和常量的声明,如下:")
                    CodeView(code: code_1).padding(10)
                    
                    
                }
            }
        }
    }
}

struct VariableView_Previews: PreviewProvider {
    static var previews: some View {
        VariableView()
    }
}
